import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import yws01.Business.*;
import yws01.Model.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.Period;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@ContextConfiguration("classpath*:database-context.xml")
public class Text extends AbstractTestNGSpringContextTests {
    @Autowired
SaleServiceCheka serviceCheka;
    @Autowired
    SaleServiceChewei serviceChewei;
    @Autowired
    SaleServiceCheweifenpei serviceCheweifenpei;
    @Autowired
    SaleServiceChezhu serviceChezhu;
    @Autowired
    SaleServiceDongtaichewei serviceDongtaichewei;
    @Autowired
    SaleServiceFeiwang serviceFeiwang;
    @Autowired
    Cheka cheka;
    @Autowired
    Chewei chewei;
    @Autowired
    Cheweifenpei cheweifenpei;
    @Autowired
    Chezhu chezhu;
    @Autowired
    Dongtaichewei dongtaichewei;
    @Autowired
    Feiwang feiwang;

    @Test
    public void insertcheka(){
       cheka.setChekabianhao(3);
       cheka.setChekaxinghao("VIP");
       cheka.setChezhubianhao(111);
       serviceCheka.Chekainsrt(cheka);
    }

@Test
    public void modifycheka(){
        cheka.setChekabianhao(3);
        cheka.setChekaxinghao("非VIP");
        cheka.setCheweibianhao(1);
        serviceCheka.Chekamodify(cheka);
}
@Test
    public void querycheka(){
        cheka.setChekabianhao(3);
        serviceCheka.Chekaquery(cheka);
}
@Test
    public void insertchewei(){
        chewei.setCheweibianhao(4);
        chewei.setCheweileixing("VIP");
        chewei.setShifouzhanyong("否");
        serviceChewei.Cheweiinsrt(chewei);
}
@Test
    public void deletechewei(){
        chewei.setCheweibianhao(3);
        serviceChewei.Cheweidelete(chewei);
}
@Test
    public void modifychewei(){
        chewei.setCheweibianhao(1);
        chewei.setCheweileixing("非VIP");
        chewei.setShifouzhanyong("否");
        serviceChewei.Cheweimodify(chewei);
}
@Test
    public void queryChewei(){
        chewei.setCheweibianhao(1);
        serviceChewei.Cheweiquery(chewei);
}
@Test
    public void insertCheweifenpei(){
        cheweifenpei.setChezhubianhao(111);
        cheweifenpei.setChekabianhao(1);
        cheweifenpei.setCheweibianhao(2);
        cheweifenpei.setChuangjianshijian("2222");
        serviceCheweifenpei.Cheweifenpeiinsert(cheweifenpei);
}
@Test
    public void deleteCheweifenpei(){
        cheweifenpei.setDingdanhao(2);
        serviceCheweifenpei.Cheweifenpeidelete(cheweifenpei);
}
    @Test
    public void insertChezhu(){
        chezhu.setChezhubianhao(333);
        chezhu.setChekabianhao(1);
        chezhu.setChezhuname("李四");
        chezhu.setLianxidianhua("64987486456");
        chezhu.setChepaihao("uysdg");
        chezhu.setMima("123");
        serviceChezhu.Chezhuinsert(chezhu);
    }
    @Test
    public void deleteChezhu(){
        chezhu.setChezhubianhao(333);
        chezhu.setMima("123");
        serviceChezhu.Chezhudelete(chezhu);
    }
    @Test
    public void queryChezhu(){
        chezhu.setChezhubianhao(333);
        serviceChezhu.Chezhuquery(chezhu);
    }
    @Test
    public void modifyChezhu(){
        chezhu.setChezhubianhao(333);
        chezhu.setMima("123");
        chezhu.setChezhuname("王五");
        chezhu.setChepaihao("adfg");
        chezhu.setLianxidianhua("999999");
        serviceChezhu.Chezhumodify(chezhu);
    }
    @Test
    public void insertDongtaichewei(){
        dongtaichewei.setCheweihao(1);
        dongtaichewei.setIntime("2020-01-02 10:25:23");
        dongtaichewei.setOuttime("2020-01-02 10:50:26");
        serviceDongtaichewei.Dongtaicheweiinsrt(dongtaichewei);
    }
    @Test
    public void modifyDongtaichewei(){
        dongtaichewei.setId(3);
        dongtaichewei.setCheweihao(1);
        dongtaichewei.setOuttime("123");
        serviceDongtaichewei.Dongtaicheweimodify(dongtaichewei);
    }
    @Test
    public void queryDongtaichewei(){
        dongtaichewei.setCheweihao(1);
        dongtaichewei.setIntime("2020-01-02 10:25:23");
        dongtaichewei.setOuttime("123");
        serviceDongtaichewei.Dongtaicheweiquery(dongtaichewei);
    }
@Test
    public void insertFeiwang(){
        feiwang.setChepaihao("123456");
        feiwang.setLianxifangshi("1110");
        feiwang.setChuangjiantime("2020-02-03 20:23:56");
        serviceFeiwang.Feiwanginsert(feiwang);
}
@Test
    public void modifyFangwang(){
        feiwang.setChepaihao("123456");
        feiwang.setFeiyong2(123);
        serviceFeiwang.Feiwangmodify(feiwang);
}
@Test
    public void queryFeiwang(){
        feiwang.setChepaihao("123456");
        serviceFeiwang.Feiwangquery(feiwang);
}
@Test
    public void shijain() throws ParseException {
    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String x="2003-02-28 23:59:59";
    java.util.Date begin=dfs.parse(x);
    java.util.Date end = dfs.parse("2003-03-01 00:00:01");
    long between=(end.getTime()-begin.getTime())/1000;
    System.out.println(between);
}
@Test
    public long shijian1(String x) throws ParseException {
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Date end=dfs.parse(x);
        java.util.Date  begin= dfs.parse("2020-01-01 00:00:00");
        long between=(end.getTime()-begin.getTime())/1000;
        System.out.println(between);
        return between;
    }
@Test
    public void cheshichazhao() throws ParseException {
        dongtaichewei.setCheweihao(4);
        dongtaichewei.setIntime("2020-06-18 10:56:12");
        dongtaichewei.setOuttime("2020-06-22 10:56:12");
        long x1=shijian1(dongtaichewei.getIntime());
        long y1=shijian1(dongtaichewei.getOuttime());
    List<Dongtaichewei> xyz1 = new ArrayList<>();
    List<Dongtaichewei> xyz=serviceDongtaichewei.Dongtaicheweiall(dongtaichewei);
    System.out.println(xyz.size());
    for (int i=0;i<xyz.size();i++)
    {
        long x=shijian1(xyz.get(i).getIntime());long y=shijian1(xyz.get(i).getOuttime());
        if(x>=x1&&y<=y1||x>=x1&&x<y1&&y>=y1||x<=x1&&y<=y1&&y>x1||x<=x1&&y>=y1)
            xyz1.add(xyz.get(i));
    }
    for (int i=0;i<xyz1.size();i++)
        System.out.println(xyz1.get(i).toString());
}
@Test
    public void shiyan() throws ParseException {
        long y=shijian1("2020-06-22 10:56:12");long x=shijian1("2020-06-18 10:56:12");
    int dd=(int)(31536000-y+x)/86400;int hh=(int)((31536000-y+x)%86400)/3600;
    String sum=dd+"天"+hh+"小时";
    System.out.println(sum);
}

}
